/**
 * @filename:SysMenuServiceImpl 2023-10-22 00:33:19
 * @project xxx系统  1.0
 * Copyright(c) 2021 fangdy Co. Ltd.
 * All right reserved.
 */
package org.fdy.bgadmin.service.impl;

import org.fdy.bgadmin.dto.RoleSmallDto;
import org.fdy.bgadmin.entity.SysMenu;
import org.fdy.bgadmin.dao.SysMenuDao;
import org.fdy.bgadmin.res.MenuRes;
import org.fdy.bgadmin.service.SysMenuService;
import org.fdy.bgadmin.service.SysRoleService;
import org.springframework.stereotype.Service;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @Description:(sys_menu服务实现)
 *
 * @version: 1.0
 * @author: fangdy
 *
 */
@Slf4j
@Service
@RequiredArgsConstructor(onConstructor_ = @Autowired)
public class SysMenuServiceImpl  extends ServiceImpl<SysMenuDao, SysMenu> implements SysMenuService  {

    private final SysRoleService roleService;

    @Override
    public List<MenuRes> buildTree(List<SysMenu> menuDtoList) {
        return null;
    }

    @Override
    public List<SysMenu> findByUser(Long currentUserId) {
        List<RoleSmallDto> roles = roleService.findByUsersId(currentUserId);
        Set<Long> roleIds = roles.stream().map(RoleSmallDto::getId).collect(Collectors.toSet());
        return this.findByRoleIdsAndTypeNot(roleIds);
    }

    @Override
    public List<SysMenu> findByRoleIdsAndTypeNot(Set<Long> roleIds) {
        return this.baseMapper.findByRoleIdsAndTypeNot(roleIds);
    }
}
